def min_deletions_to_make_elements_equal(arr):
    # 哈希表用于记录每个元素的频率
    frequency = {}
    
    # 统计每个元素的频率
    for num in arr:
        if num in frequency:
            frequency[num] += 1
        else:
            frequency[num] = 1
    
    # 找到最大频率
    max_freq = max(frequency.values())
    
    # 计算需要删除的元素数量
    min_deletions = len(arr) - max_freq
    
    return min_deletions

# 测试例子
arr1 = [4, 3, 4, 4, 2, 4]
print(min_deletions_to_make_elements_equal(arr1))  # 输出：2

arr2 = [1, 2, 3, 4, 5]
print(min_deletions_to_make_elements_equal(arr2))  # 输出：4